/*****************************************************************************
 *
 * Copyright (c), 2004-2020,ShangHai Neotune Information Technology Co., Ltd.
 *
 * Module Name : envoy.h
 *
 * Author :    sean
 *
 * Date :    2004-02-05
 *
 * Version :    1.00
 *
 * Description :    
 *
 * Other :    
 *
 * Data Structure List: <Main Data Structure>
 *
 * Modification History
 * ---------------------------------------------------------------------------
 *  1: Data :      2004-02-05
 *    Author :     sean
 *    Version :    V100R001M00
 *    Modification : creation
 *
*****************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

#include "neos_vx_win.h"


#include <windows.h>



#ifdef CONFIG_PREAMBLE

/*****************************************************************
 *
 * System Includes:
 *
 *     The SNMP uses memcpy(), memset(), and strlen().  The appropriate
 * include file should be put here to see that these routines are
 * properly declared.  If no such include file exists on the system
 * then declare memcpy() and memset() here directly.  The SNMP also
 * uses min() and max().  Include the system's definition or use the
 * macros supplied below.
 *****************************************************************/
#include <string.h>



/*****************************************************************
 * Memory allocation routines.  The SNMP needs to allocate memory to
 * decode the packet into and also to store the response data for GET's
 * and GET-NEXT's.
 *****************************************************************/

/*----------------------------------------------------------------
 * Make sure that the routines used by the SNMP_memory_alloc() and
 * SNMP_memory_free() macros are declared.  If system memory routines
 * are used (e.g. malloc() and free()) then include the appropriate
 * system header file here.
 ----------------------------------------------------------------*/
extern  void * SNMP_MemoryAlloc (size_t);
extern  STATUS   SNMP_MemoryFree (void *);

#define SNMP_memory_alloc(p)     SNMP_MemoryAlloc(p)
#define SNMP_memory_free(p)      SNMP_MemoryFree (p)




/* Define the maximum packet size this implementation will accept.      */
/* There is no hard upper limit.  SNMP_MAX_PACKET_SIZE should not be    */
/* reduced below the value of SNMP_MIN_PACKET_SIZE.                     */

/* xxxxxxxxxxxxxxxxxxxxxxxxxxx*/

#define SNMP_MAX_PACKET_SIZE            (8*1024)
#define SNMP_MIN_PACKET_SIZE            484 /* shouldn't change */

/* Say what is the maximum number of components of an object identifer  */
/* which we can handle, including those in the instance.                */
#define MAX_OID_COUNT                   32

#if (INSTALL_ENVOY_SNMP_LOCK)
typedef SEM_ID ENVOY_LOCK_T;
#endif 


#define ENVOY_SA_SET_TIMEOUT 100000

#else   /* CONFIG_PREAMBLE */

/*****************************************************************
 *
 * The following macro definitions allow access to the user configurable
 * part of the SNMP code.
 *
 *****************************************************************/

/*****************************************************************
 * Include any declarations needed for the routines specified below
 * by the macros.  Don't put <snmp.h> here because this file is
 * included by that one.
 *****************************************************************/

/*----------------------------------------------------------------
 SNMP_validate_community -- Check an operation against the community name.
         
Parameters:
        SNMP_PKT_T *pkt         The received packet (decoded format)
        SNMPADDR_T *src         Source of the packet
        SNMPADDR_T *dst         Destination of the packet (most likely
                                the address of the machine on which this
                                code is running.)

Returns:
        This procedure should return 0 if happy with the community and
        1 if not.

        This routine should fill in the packet structure with the mib
        view mask associated with the community string.
        This routine may hang additional data onto the "private" field of
        the packet structure.  The user will be given the opportinity to
        release that memory via SNMP_release_private().

 ----------------------------------------------------------------*/

 
#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)

#if 0   /* not supported for vxWorks agent */

#include <envoy/utils/nvutils.h>

#define SNMP_VIEW_CREATE_TEST(PKT, NEW)         SNMP_NV_View_Add_Mod(NEW, 0)
#define SNMP_VIEW_UPDATE_TEST(PKT, OLD, NEW)    SNMP_NV_View_Add_Mod(NEW, 0)
#define SNMP_VIEW_DESTROY_TEST(PKT, OLD)        SNMP_NV_View_Add_Mod(OLD, 1)
#define SNMP_VIEW_BACKOUT_HOOK(NEW)             SNMP_NV_Clean()
#define SNMP_VIEW_CREATE_UNDO(NEW)              (SNMP_NV_Clean(), 0)
#define SNMP_VIEW_UPDATE_UNDO(OLD, NEW)         (SNMP_NV_Clean(), 0)
#define SNMP_VIEW_DESTROY_UNDO(OLD)             (SNMP_NV_Clean(), 0)
#define SNMP_VIEW_DESTROY_BACKOUT(OLD)          SNMP_NV_Clean()
#define SNMP_VIEW_FINISHED                      SNMP_NV_Doit()


#endif  /* 0 (not supported for vxWorks agent) */

#endif /* version2, master agent, v2 views */

#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
#include "nvutils.h"

#define SNMP_VIEW_2275_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_view_2275_test(PKT, VBP, CUR, NEW)
#define SNMP_VIEW_2275_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_view_2275_test(PKT, VBP, CUR, NEW)
#define SNMP_VIEW_2275_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_view_2275_test(PKT, VBP, CUR, NEW)

#define SNMP_VIEW_2275_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_view_2275_set(PKT, VBP, CUR, NEW)
#define SNMP_VIEW_2275_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_view_2275_set(PKT, VBP, CUR, NEW)
#define SNMP_VIEW_2275_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_view_2275_set(PKT, VBP, CUR, NEW)

#define SNMP_VIEW_2275_DESTROY_BACKOUT(CUR, NEW)         \
                        SNMP_view_2275_backout(CUR, NEW)
#define SNMP_VIEW_2275_CREATE_BACKOUT(CUR, NEW)          \
                        SNMP_view_2275_backout(CUR, NEW)
#define SNMP_VIEW_2275_UPDATE_BACKOUT(CUR, NEW)          \
                        SNMP_view_2275_backout(CUR, NEW)

#define SNMP_VIEW_2275_CREATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_view_2275_undo(PKT, VBP, CUR, SAV)
#define SNMP_VIEW_2275_UPDATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_view_2275_undo(PKT, VBP, CUR, SAV)
#define SNMP_VIEW_2275_DESTROY_UNDO(PKT, VBP, CUR, SAV)  \
                        SNMP_view_2275_undo(PKT, VBP, CUR, SAV)

#define SNMP_VIEW_2275_FINISHED() SNMP_view_2275_finished()

#endif /* #if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS) */


/*****************************************************************
 If version 3 is installed we may need the following macros.

 ENVOY_TIME - returns a clock with a granularity of seconds
  PARAMETERS: none
  returns:    bits32_t

 SNMP_validate_address
  This routine gives the user a chance to examine the address
  information as well as most of the packet itself before a v3
  packet is processed.  The routine must attach the address
  information to the packet.  It may attach a non-default mib
  tree if desired.  Note: in some SNMP_ERROR cases the packet will
  not be decoded when this routine is called.

  Parameters:
        SNMP_PKT_T *pkt         The received packet (decoded format)
        SNMPADDR_T *src         Source of the packet
        SNMPADDR_T *dst         Destination of the packet (most likely
                                the address of the machine on which this
                                code is running.)
  returns:
        0 - SNMP_OK
        1 - failure, drop the packet


 Lastly are are a series of macros that will connect the method
 routines we supplied for the v3 tables to your non-volatile
 storage areas.  You should consult the manuals for more information
 about these macros.
*****************************************************************/
#if INSTALL_ENVOY_SNMP_VERSION_3
#include <nvutils.h>

extern bits32_t SNMP_SecsGet(void);
#define ENVOY_TIME() SNMP_SecsGet()


extern int SNMP_IoAddressValidate __((SNMP_PKT_T *, SNMPADDR_T *, \
                                                SNMPADDR_T *));
#define SNMP_validate_address(pkt, src, dst) \
    SNMP_IoAddressValidate (pkt, src, dst)
#if INSTALL_ENVOY_SNMP_V3_NOTIFY

extern int SNMP_TargetAddrToSnmpAddr(SNMPADDR_T *, OBJ_ID_T *, EBUFFER_T *);
extern int SNMP_SnmpAddrToTargetAddr(SNMPADDR_T *, OBJ_ID_T *, EBUFFER_T *);

#define ENVOY_TADDRESS_TO_SNMPADDR(A, D, T) \
        SNMP_TargetAddrToSnmpAddr(A, D, T)


#define ENVOY_SNMPADDR_TO_TADDRESS(A, D, T) \
        SNMP_SnmpAddrToTargetAddr(A, D, T)
#endif

#define SNMP_V3_GROUP_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_group_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_GROUP_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_group_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_GROUP_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_group_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_GROUP_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_group_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_GROUP_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_group_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_GROUP_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_group_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_GROUP_DESTROY_BACKOUT(CUR, NEW)  \
                        SNMP_v3_group_backout(CUR, NEW)
#define SNMP_V3_GROUP_CREATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_group_backout(CUR, NEW)
#define SNMP_V3_GROUP_UPDATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_group_backout(CUR, NEW)

#define SNMP_V3_GROUP_CREATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_group_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_GROUP_UPDATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_group_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_GROUP_DESTROY_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_group_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_GROUP_FINISHED() SNMP_v3_group_finished()


#define SNMP_V3_ACCESS_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_access_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_ACCESS_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_access_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_ACCESS_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_access_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_ACCESS_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_access_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_ACCESS_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_access_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_ACCESS_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_access_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_ACCESS_DESTROY_BACKOUT(CUR, NEW)         \
                        SNMP_v3_access_backout(CUR, NEW)
#define SNMP_V3_ACCESS_CREATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_access_backout(CUR, NEW)
#define SNMP_V3_ACCESS_UPDATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_access_backout(CUR, NEW)

#define SNMP_V3_ACCESS_CREATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_access_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_ACCESS_UPDATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_access_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_ACCESS_DESTROY_UNDO(PKT, VBP, CUR, SAV)  \
                        SNMP_v3_access_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_ACCESS_FINISHED() SNMP_v3_access_finished()


#define SNMP_V3_USER_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_user_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_USER_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_user_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_USER_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_user_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_USER_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_user_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_USER_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_user_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_USER_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_user_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_USER_DESTROY_BACKOUT(CUR, NEW)   \
                        SNMP_v3_user_backout(CUR, NEW)
#define SNMP_V3_USER_CREATE_BACKOUT(CUR, NEW)            \
                        SNMP_v3_user_backout(CUR, NEW)
#define SNMP_V3_USER_UPDATE_BACKOUT(CUR, NEW)            \
                        SNMP_v3_user_backout(CUR, NEW)

#define SNMP_V3_USER_CREATE_UNDO(PKT, VBP, CUR, SAV)     \
                        SNMP_v3_user_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_USER_UPDATE_UNDO(PKT, VBP, CUR, SAV)     \
                        SNMP_v3_user_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_USER_DESTROY_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_user_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_USER_FINISHED() SNMP_v3_user_finished()

#define SNMP_V3_TADDR_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_taddr_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_TADDR_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_taddr_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_TADDR_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_taddr_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_TADDR_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_taddr_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_TADDR_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_taddr_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_TADDR_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_taddr_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_TADDR_DESTROY_BACKOUT(CUR, NEW)  \
                        SNMP_v3_taddr_backout(CUR, NEW)
#define SNMP_V3_TADDR_CREATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_taddr_backout(CUR, NEW)
#define SNMP_V3_TADDR_UPDATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_taddr_backout(CUR, NEW)

#define SNMP_V3_TADDR_CREATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_taddr_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_TADDR_UPDATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_taddr_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_TADDR_DESTROY_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_taddr_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_TADDR_FINISHED() SNMP_v3_taddr_finished()

#define SNMP_V3_TPARAM_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_tparam_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_TPARAM_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_tparam_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_TPARAM_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_tparam_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_TPARAM_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_tparam_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_TPARAM_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_tparam_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_TPARAM_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_tparam_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_TPARAM_DESTROY_BACKOUT(CUR, NEW)         \
                        SNMP_v3_tparam_backout(CUR, NEW)
#define SNMP_V3_TPARAM_CREATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_tparam_backout(CUR, NEW)
#define SNMP_V3_TPARAM_UPDATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_tparam_backout(CUR, NEW)

#define SNMP_V3_TPARAM_CREATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_tparam_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_TPARAM_UPDATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_tparam_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_TPARAM_DESTROY_UNDO(PKT, VBP, CUR, SAV)  \
                        SNMP_v3_tparam_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_TPARAM_FINISHED() SNMP_v3_tparam_finished()

#define SNMP_V3_NOTIFY_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_notify_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NOTIFY_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_notify_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NOTIFY_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_notify_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_NOTIFY_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_notify_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NOTIFY_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_notify_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NOTIFY_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_notify_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_NOTIFY_DESTROY_BACKOUT(CUR, NEW)         \
                        SNMP_v3_notify_backout(CUR, NEW)
#define SNMP_V3_NOTIFY_CREATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_notify_backout(CUR, NEW)
#define SNMP_V3_NOTIFY_UPDATE_BACKOUT(CUR, NEW)          \
                        SNMP_v3_notify_backout(CUR, NEW)

#define SNMP_V3_NOTIFY_CREATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_notify_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NOTIFY_UPDATE_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_notify_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NOTIFY_DESTROY_UNDO(PKT, VBP, CUR, SAV)  \
                        SNMP_v3_notify_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_NOTIFY_FINISHED() SNMP_v3_notify_finished()

#define SNMP_V3_NPROF_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_nprof_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NPROF_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nprof_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NPROF_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nprof_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_NPROF_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_nprof_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NPROF_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nprof_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NPROF_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nprof_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_NPROF_DESTROY_BACKOUT(CUR, NEW)  \
                        SNMP_v3_nprof_backout(CUR, NEW)
#define SNMP_V3_NPROF_CREATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_nprof_backout(CUR, NEW)
#define SNMP_V3_NPROF_UPDATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_nprof_backout(CUR, NEW)

#define SNMP_V3_NPROF_CREATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_nprof_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NPROF_UPDATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_nprof_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NPROF_DESTROY_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_nprof_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_NPROF_FINISHED() SNMP_v3_nprof_finished()

#define SNMP_V3_NFILT_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_nfilt_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NFILT_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nfilt_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_NFILT_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nfilt_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_NFILT_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_nfilt_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NFILT_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nfilt_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_NFILT_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_nfilt_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_NFILT_DESTROY_BACKOUT(CUR, NEW)  \
                        SNMP_v3_nfilt_backout(CUR, NEW)
#define SNMP_V3_NFILT_CREATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_nfilt_backout(CUR, NEW)
#define SNMP_V3_NFILT_UPDATE_BACKOUT(CUR, NEW)           \
                        SNMP_v3_nfilt_backout(CUR, NEW)

#define SNMP_V3_NFILT_CREATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_nfilt_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NFILT_UPDATE_UNDO(PKT, VBP, CUR, SAV)    \
                        SNMP_v3_nfilt_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_NFILT_DESTROY_UNDO(PKT, VBP, CUR, SAV)   \
                        SNMP_v3_nfilt_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_NFILT_FINISHED() SNMP_v3_nfilt_finished()

#define SNMP_V3_PROXY_DESTROY_TEST(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_proxy_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_PROXY_CREATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_proxy_test(PKT, VBP, CUR, NEW)
#define SNMP_V3_PROXY_UPDATE_TEST(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_proxy_test(PKT, VBP, CUR, NEW)

#define SNMP_V3_PROXY_DESTROY_SET(PKT, VBP, CUR, NEW)                   \
                        SNMP_v3_proxy_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_PROXY_CREATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_proxy_set(PKT, VBP, CUR, NEW)
#define SNMP_V3_PROXY_UPDATE_SET(PKT, VBP, CUR, NEW)                    \
                        SNMP_v3_proxy_set(PKT, VBP, CUR, NEW)

#define SNMP_V3_PROXY_DESTROY_BACKOUT(CUR, NEW)                         \
                        SNMP_v3_proxy_backout(CUR, NEW)
#define SNMP_V3_PROXY_CREATE_BACKOUT(CUR, NEW)                          \
                        SNMP_v3_proxy_backout(CUR, NEW)
#define SNMP_V3_PROXY_UPDATE_BACKOUT(CUR, NEW)                          \
                        SNMP_v3_proxy_backout(CUR, NEW)

#define SNMP_V3_PROXY_CREATE_UNDO(PKT, VBP, CUR, SAV)                   \
                        SNMP_v3_proxy_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_PROXY_UPDATE_UNDO(PKT, VBP, CUR, SAV)                   \
                        SNMP_v3_proxy_undo(PKT, VBP, CUR, SAV)
#define SNMP_V3_PROXY_DESTROY_UNDO(PKT, VBP, CUR, SAV)                  \
                        SNMP_v3_proxy_undo(PKT, VBP, CUR, SAV)

#define SNMP_V3_PROXY_FINISHED()      SNMP_v3_proxy_finished()

#endif /* #if INSTALL_ENVOY_SNMP_VERSION_3 */

#if (INSTALL_ENVOY_EPI_MASTER)
#define SNMP_RESETSYSUPTIME
#endif

/* here are the routines that agentx requires */
#if INSTALL_ENVOY_AGENTX_MASTER

/* first we do the master agentx macros */
extern bits32_t envoyGetSysUpTime();
extern sbits32_t envoyAxTransportType(ptr_t);
extern int       envoyAxTransportString(ptr_t, ALENGTH_T *,
                                        bits8_t **, int *);

#define ENVOY_GET_SYSUPTIME(CON) envoyGetSysUpTime(CON)
#define ENVOY_AX_TRANSPORT_TYPE(COOKIE)   envoyAxTransportType(COOKIE)
#define ENVOY_AX_TRANSPORT_STRING(COOKIE, NEED, BUF, DYN) \
        envoyAxTransportString(COOKIE, NEED, BUF, DYN)
#define ENVOY_AX_TRANSPORTS_SUPPORTED    {0}

/* Default values are fine for us */
/*
#define ENVOY_AX_DEFAULT_TIMEOUT 1

#define ENVOY_AX_FIND_MIB(CONTEXT) (EBufferUsed(CONTEXT) ? 0 : &mib_root_node)

#define ENVOY_AX_MA_AC_ADD(PKTP, MIBROOT)    GEN_ERR
#define ENVOY_AX_MA_AC_REMOVE(PKTP, MIBROOT) GEN_ERR
#define ENVOY_AX_MA_AC_CLEAN(SESS_ID)
*/
#endif /* #if INSTALL_ENVOY_AGENTX_MASTER */

#if INSTALL_ENVOY_AGENTX_SUB
/* then we do the subagent agentx macros */
#define ENVOY_AX_SA_MIB_ROOT_NODE(CKE, PKT) envoy_ax_sa_mib_root_node(CKE, PKT)
#define ENVOY_AX_SA_TIMEOUT 1000

#endif /* #if INSTALL_ENVOY_AGENTX_SUB */



/*----------------------------------------------------------------
 SNMP_release_private -- Get rid of a any private data attached to the packet
                    structure.  May be left undefined in which case nothing
                    is done with the private field when the SNMP packet
                    structure is freed.

 Parameters:
        SNMP_PKT_T *pkt         The packet itself

 Returns: Nothing
 ----------------------------------------------------------------*/

extern  void SNMP_HookPrivRelease __((SNMP_PKT_T*));
#define SNMP_release_private(pkt)  SNMP_HookPrivRelease (pkt)
 



/*----------------------------------------------------------------
 SNMP_user_get_encode_buffer -- Allows the user the opportunity to get the
                        buffer that the SNMP packet will be encoded into.
                        If not used then leave undefined.

 Parameters:
        SNMP_PKT_T      *pkt    The packet being encoded.
        unsigned int    need    The amount of storage needed.
        EBUFFER_T       *ebuffp The ebuffer to fill in with the actual
                                buffer.

 Returns:
        0   successful
        1   not successful
 ----------------------------------------------------------------*/
/* #define SNMP_user_get_encode_buffer(pkt, need, ebuffp) 0 */


/*----------------------------------------------------------------
 SNMP_trace_input
 SNMP_trace_output
                -- for implementing packet tracing through the
                   SNMP code.  May not be left undefined but may
                   instead be defined as nothing.

 Parameters:
        SNMP_PKT_T *pkt         The packet being traced

 Returns: Nothing

 ----------------------------------------------------------------*/

extern void SNMP_TraceInput (SNMP_PKT_T *);

#define SNMP_TRACE_INPUT(pkt)   // yutao SNMP_TraceInput (pkt)
#define SNMP_TRACE_OUTPUT(pkt)

/*****************************************************************
 * The next series of macros are hooks into the processing of SET PDUs.
 * For most uses you should be able to leave these undefined.
 *****************************************************************/

/*----------------------------------------------------------------
 SNMP_validate_set_pdu -- Perform a global validation of a SET PDU.
         
 Parameters:
        SNMP_PKT_T *pkt         The packet itself

 Returns:
         -1 If the PDU is bad and should be rejected with a GEN_ERR.
          0 If the PDU is good and normal handling should proceed.
         +1 If the PDU is good and this routine has performed all of
            the set operations internally.
 ----------------------------------------------------------------*/

extern int SNMP_HookSetPduValidate   __((SNMP_PKT_T*));
#define SNMP_validate_set_pdu(pkt) SNMP_HookSetPduValidate (pkt)
  

/*----------------------------------------------------------------
 SNMP_user_pre_set -- Perform a global validation of a SET PDU after all of the
                 test procedures have been called and given the "go ahead".
         
 Parameters:
        SNMP_PKT_T *pkt         The packet itself

 Returns:
         -1 If the PDU is bad and should be rejected with a GEN_ERR.
          0 If the PDU is good and normal handling should proceed.
         +1 If the PDU is good and this routine has performed all of
            the set operations internally.
 ----------------------------------------------------------------*/


extern  int SNMP_HookPreSet   __((SNMP_PKT_T*));
#define SNMP_user_pre_set(pkt) SNMP_HookPreSet(pkt)




/*----------------------------------------------------------------
 SNMP_user_post_set -- Perform any final activities after all of the set
                  procedures have been called.

 Parameters:
        SNMP_PKT_T *pkt         The packet itself

 Returns: Nothing
 ----------------------------------------------------------------*/


extern  int SNMP_HookPostSet   __((SNMP_PKT_T*));
#define SNMP_user_post_set   SNMP_HookPostSet

/*************************************************************************************
* set failed routine
*/

extern int SNMP_HookSetFailed   __((SNMP_PKT_T*));
#define SNMP_user_set_failed           SNMP_HookSetFailed




#if (INSTALL_ENVOY_SNMP_LOCK)
 
#define ENVOY_SNMP_LOCK(name)                ENVOY_LOCK_T name 
#define ENVOY_SNMP_LOCK_EXTERN(name)         extern  ENVOY_LOCK_T name
 
#define ENVOY_SNMP_INIT_LOCK(name)           (name) = semBCreate (SEM_Q_PRIORITY, SEM_FULL)

#define ENVOY_SNMP_FREE_LOCK_TAG(name, tag)  semDelete ((name))

#define ENVOY_SNMP_GET_READ_LOCK(name)       semTake (name, WAIT_FOREVER)
#define ENVOY_SNMP_GET_WRITE_LOCK(name)      semTake (name, WAIT_FOREVER)
#define ENVOY_SNMP_RELEASE_READ_LOCK(name)   semGive (name)
#define ENVOY_SNMP_RELEASE_WRITE_LOCK(name)  semGive (name)

#endif /* (INSTALL_ENVOY_SNMP_LOCK) */


extern bits32_t SNMP_EnvoyNow        __((void));

#define ENVOY_NOW()             SNMP_EnvoyNow()






#define snmpdGroupByGetprocAndInstance group_by_getproc_and_instance  
#define snmpdVbRowLooseExtract         vb_extract_row_loose           
#define snmpdVbRowExtract              vb_extract_row                 
#define snmpdContinue                  SNMP_Continue_function         



#endif /* CONFIG_PREAMBLE */

#ifdef __cplusplus
}
#endif  /* __cplusplus */
